package edu.mis.model;

import java.util.*;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import edu.mis.model.base.BaseOrderDetail;


@SuppressWarnings("serial")
public class OrderDetail extends BaseOrderDetail<OrderDetail>{


	public static final OrderDetail dao = new OrderDetail().dao();

    private Commodity commodity;
    private OrderList orderList;


	/**
	 * 表关联查询得到菜品的菜品号
	 * 类型：订单为1：N关系，得到菜品对象的类型
	 * @return
	 */
	public List<Record> findAllOrderDetailsWithCommodity(String commodityId){
		return Db.find("SELECT d.id,d.qty,c.commodityName,c.price FROM(SELECT * FROM order_detail  WHERE commodityId=?) d LEFT JOIN commodity c on d.commodityId=c.id",commodityId);
	}


	public List<Record> findAllRecord() {
        return Db.find("SELECT d.*,c.commodityName,c.price FROM order_detail d LEFT JOIN commodity c ON d.commodityId=c.id");
	}


	public List<OrderDetail> findAll(){
		return OrderDetail.dao.find("SELECT * FROM order_detail");
	}


	public OrderList findOrderListByOrderListId() {
		return OrderList.dao.findById(get("orderListId"));
	}

	/**
	 * 表关联查询_得到订单详细的菜品
	 * 权限:用户为1:N关系，得到订单详细的菜品对象。
	 * @return
	 */
	public Commodity findCommodityByCommodityId(Integer commodityId){
		return Commodity.dao.findById(commodityId);
	}

	public void setCommodity(Commodity commodity) {
		this.setCommodityId(commodity.getId());
		this.commodity = commodity;

	}

	public Commodity getCommodity() {
		return commodity;
	}

	public OrderList getOrderList() {
		return orderList;
	}

	public void setOrderList(OrderList orderList) {
		this.setOrderListId(orderList.getId());
		this.orderList = orderList;
	}



}
